<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/SHA-1.js"></script>
		<script type="text/javascript" src="../../../JS/BasicInfomation.js"></script>
		<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	</head>

	<body style="padding:0px;background-color: white">
		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div>
			<form id="ff" method="post">
				<table id="basicInfo" cellpadding="5" class="displaytable" style="text-align: left;">
					<tr>
						<td width="15%"><h id="star">* </h>设备名称</td>
						<td width="35%">
							<input class="easyui-textbox" style="width: 100%;" type="text" name="NAME" id="input_NAME" data-options="required:true" />
						</td>
						<td width="15%"><h id="star">* </h>设备类型</td>
						<td width="35%">
							<input class="easyui-combobox" style="width:87%;" type="text" name="DEVICE_TYPE" id="input_DEVICE_TYPE" data-options="panelHeight: '150',required:true,url:RemoteLinkAddress + '/market/devicetype/listall.do',method:'get',valueField:'NAME',textField:'NAME'" />
							<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="AddEquipmentType()"></a>
						</td>
					</tr>
					<tr>
						<td><h id="star">* </h>生产日期</td>
						<td>
							<input class="easyui-datebox" style="width: 100%;" type="text" name="PRODUCTION_TIME" id="input_PRODUCTION_TIME" data-options="required:true" />
						</td>
						<td><h id="star">* </h>使用年限(年)</td>
						<td>
							<input class="easyui-numberbox" style="width:100%;" name="SERVICELIFE" id="input_SERVICELIFE" data-options="suffix:'年',precision: 1,required:true" />
						</td>
					</tr>
					<tr>
						<td><h id="star">* </h>责任人</td>
						<td>
							<input class="easyui-textbox" style="width:100%;" type="text" name="DEVICE_RP" id="input_DEVICE_RP" data-options="required:true" />
						</td>
						<td><h id="star">* </h>维护周期(年/次)</td>
						<td>
							<input class="easyui-numberbox" style="width:100%;" type="text" name="SERVICE_INTERVALS" id="input_SERVICE_INTERVALS" data-options="suffix:'年',precision: 1,required:true" />
						</td>
					</tr>
					<tr class="hiddentr">
						<td>ID</td>
						<td>
							<input style="width:100%" class="easyui-textbox" id="input_ID"></input>
						</td>
						<td>设备编号</td>
						<td>
							<input style="width:100%" class="easyui-textbox" id="input_DEVICE_NO"></input>
						</td>
					</tr>
				</table>
				<div id="new_footer" style="margin-top: 30px;">

				</div>
			</form>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 40%;height: 450px;" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>
	<script type="text/javascript">
		var currid = AddFlag;
		var id = getID();
		var currPage = 0; //当前的页数
		var MaxPage = 0;
		var MinPage = 1;
		var isVerify = 0;
		var AddDialog;
		$(document).ready(function(){
		if(id != AddFlag && id != undefined) {
			currid = id;
			loadRemote();
		}
       });
		getPageMaxAndMin();
		addDialogFooter($("#new_footer"));
		
		var detailData = [{
			"icon": "icon-undo",
			"func": "cls()",
			"functionname": "清空"
		}]
		var receipts_type = RECEIPT_FRONT_SYMBOL;
		receipts_type += RECEIPT_NEXT_SYMBOL;
		receipts_type += RECEIPT_ADD_SYMBOL;
		receipts_type += RECEIPT_SAVE_SYMBOL;
		receipts_type += RECEIPT_DELETE_SYMBOL;
		receipts_type += RECEIPT_UNVERIFY_SYMBOL;
		receipts_type += RECEIPT_VERIFY_SYMBOL;
		receipts_type += RECEIPT_PRINT_SYMBOL;
		receipts_type += RECEIPT_EXPORT_SYMBOL;
		content = AddReceiptsToolBar(receipts_type, detailData);
		$("#toolbar").append(content);
		
		function getPageMaxAndMin() {
			var _url = RemoteLinkAddress + "/market/device/getmaxminid.do";
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result != null) {
						MaxPage = result.MAXID;
						MinPage = result.MINID;
						currPage = result.MINID + 1;
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}
		
		//导出
		function exportExcel(){
			if(currid === AddFlag) {
				$.messager.alert("警告", "该订单为新增订单，无法导出Excel！");
				return;
			}
			$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						data: {
							"ID": currid
						},
						url: RemoteLinkAddress + "/market/device/excelorder.do",
						dataType: "json", //服务器返回的数据类型
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
						}
					});
				}
			});
		}

		function newdata() { //新建
			$("#verifydisplay").empty(); //去掉审核或者未审核的图片
			isVerify = 0; //将状态改为未审核
			currid = AddFlag;
			currPage = 0;
			resetData();
		}
		
		function frontpage() { //上一张
			if(currPage > MinPage) {
				var _url = RemoteLinkAddress + '/market/device/pre.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示","没有上张");
			}
		}

		function nextpage() { //下一张
			if(currPage < MaxPage) {
				var _url = RemoteLinkAddress + '/market/device/next.do?ID=' + currPage;
				getRemoteData(_url);
			} else {
				$.messager.alert("提示","没有下张");
			}
		}
		
		function save() { //保存
			if(isVerify === "1") {
				$.messager.alert("提示", "该单据已审核，不能修改！");
				return;
			}
			var isValid = $("#ff").form('validate');
			if(!isValid) {
				$.messager.alert("警告", "有必填项没有填写");
				return;
			}
			if(currid != AddFlag){
				getUpdateData();
			} else {
				getSaveData();
			}
		}
		
		function deletedata() { //删除
			if(isVerify === "1") {
				$.messager.alert("提示", "该单据已审核，不能删除！");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("提示", "该页面为新增页面，不能进行删除操作！");
				return;
			}
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/device/delete.do", {
							ID: currid,
						},
						function(result) {
							if(result.msg == "success") {
								$.messager.alert({ // show success message
									title: '成功',
									msg: '删除成功'
								});
								nextpage();
								reloadList();
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function verifydata() { //审核单据
			if(isVerify === "1") {
				$.messager.alert("警告", "已经审核无须再审");
				return;
			}
			if(currid == AddFlag) {
				$.messager.alert("提示", "该页面为新增页面，不能进行审核操作！");
				return;
			}
			var _url = RemoteLinkAddress + "/market/device/verify.do";
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: {
					ID: currid
				},
				type: "POST",
				success: function(result) {
					$.messager.alert("成功", "审核成功");
					isVerify = "1";
					verifyStatus_Market(isVerify, true);
					reloadList();
				},
				error: function(result) {
					$.messager.alert("失败", "审核失败");
				}
			});
		}

		function unverifydata() { //弃审单据
			if(currid == AddFlag) {
				$.messager.alert("提示", "该页面为新增页面，不能进行弃审操作！");
				return;
			}
			if(isVerify === "0") {
				$.messager.alert("警告", "已经弃审无须再弃审");
				return;
			}
			$.messager.confirm("警告", "你确认要弃审该条单据吗", function(r) {
				if(r) {
					var _url = RemoteLinkAddress + "/market/device/unverify.do";
					$.ajax({
						dataType: 'JSON',
						url: _url,
						data: {
							ID: currid
						},
						type: "POST",
						success: function(result) {
							$.messager.alert("成功", "弃审成功");
							isVerify = "0";
							verifyStatus_Market(isVerify, true);
							reloadList();
						},
						error: function(result) {
							$.messager.alert("失败", "弃审失败");
						}
					});
				}
			});
		}

		function print() { //打印
			var pLocation = "";
			if(currid == AddFlag) {
				$.messager.alert('警示', "当前页面为新增页面，不能进行打印操作！！");
				return;
			}
			if(isVerify === "0") {
				$.messager.alert("警告", "单据未审核，不能打印！");
				return;
			}
			var pLocation = "EquipmentManagementPrint.html?id=" + currid;
			window.open(pLocation); /*打开pLocation中的链接html文档*/
		}
		
		function loadRemote() {
			var _url = RemoteLinkAddress + '/market/device/findbyid.do?ID=' + currid;
			getRemoteData(_url);
		}

		function cls() {
			$('#ff').form('reset');
		}

		function getSaveData() {
			var data = submitFormData();
			submitData(data);
		}

		function getUpdateData() {
			var data = submitFormData();
			submitData(data);
		}

		function submitData(_data) {
			var _url = "";
			if(currid == AddFlag) {
				_url = RemoteLinkAddress + "/market/device/save.do";
			} else {
				_url = RemoteLinkAddress + "/market/device/update.do";
			}
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data:  _data,
				type: "POST",
				success: function(result) {
					reloadList();
					$.messager.alert("提示信息", "保存成功");
				},
				error: function(result) {
					$.messager.alert("错误信息", "保存失败");
				}
			});
		}

		function AddEquipmentType() {
			var pLocation = "../../Market/DictData/DictDataAdd.html?id=devicetype";
			$("#ifrmEdit").attr("src", pLocation);
			constructcomboDialog($("#dlg"), "添加基础信息", $("#input_DEVICE_TYPE"));
			AddDialog.dialog('open');
		}
		
		function getRemoteData(_url) {
			$.ajax({
				type: "get",
				url: _url,
				dataType: "json",
				success: function(result) {
					if(result == null) {
						$.messager.alert("提示", "没有下张");
						return;
					}
					if(result != null) {
						isVerify = result.ISVERIFY;
						verifyStatus_Market(isVerify, true);
						currPage = result.ID;
						currid = result.ID;
						getFormData(result);
						getDialogFooterData(result);
					}
				},
				error: function(xhr, status, error) {
					$.messager.alert("错误", "请求失败!");
				}
			});
		}
		
		//刷新list页面
		function reloadList(){
			var parentLocation;
			parentLocation = searchParent("EquipmentManagementList.html");
			data = parentLocation.redodata();
			if(currid == AddFlag){
				parentLocation.dialogClose();
			}
		}
	</script>

</html>